/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.buzzwords.entities;

import java.io.Serializable;
import java.util.Date;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

/**
 *
 * @author potlow
 */
@Entity
@Table(name = "user_table")
@NamedQueries(@NamedQuery(name="UserJPO.findByEmail", query="SELECT u FROM UserJPO u WHERE u.email = :email"))
public class UserJPO implements Serializable {

    private static final long serialVersionUID = 1L;
    private Integer id;
    private String email;
    private byte[] password;
    private Date creationTime;
    private Date lastLogin;
    private List<BuzzwordJPO> buzzwords;

    public UserJPO() {
    }

    public UserJPO(Integer id) {
        this.id = id;
    }

    public UserJPO(String email, byte[] password) {
        this.email = email;
        this.password = password;
    }

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "id")
    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    @Basic(optional = false)
    @Column(name = "email")
    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    @Basic(optional = false)
    @Column(name = "password")
    public byte[] getPassword() {
        return password;
    }

    public void setPassword(byte[] password) {
        this.password = password;
    }

    @Basic(optional = false)
    @Column(name = "creation_time")
    @Temporal(TemporalType.TIMESTAMP)
    public Date getCreationTime() {
        return creationTime;
    }

    public void setCreationTime(Date creationTime) {
        this.creationTime = creationTime;
    }

    @Column(name = "last_login")
    @Temporal(TemporalType.DATE)
    public Date getLastLogin() {
        return lastLogin;
    }

    public void setLastLogin(Date lastLogin) {
        this.lastLogin = lastLogin;
    }

    @OneToMany(mappedBy = "user", fetch=FetchType.LAZY)
    public List<BuzzwordJPO> getBuzzwords() {
        return buzzwords;
    }

    public void setBuzzwords(List<BuzzwordJPO> buzzwords) {
        this.buzzwords = buzzwords;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof UserJPO)) {
            return false;
        }
        UserJPO other = (UserJPO) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.buzzwords.persist.User[id=" + id + "]";
    }

}
